package com.ruoyi.web.controller.vidiomonitor;
/**
 * ClassName: VideoAppController <br/>
 * Description: <br/>
 * date: 2020/12/31 16:29<br/>
 *
 * @author Hesion<br />
 * @version
 * @program: ruoyi
 * @description: 视频应用服务
 * @author: hesion
 * @create: 2020-12-31 16:29
 * @program: ruoyi
 * @description: 视频应用服务
 * @author: hesion
 * @create: 2020-12-31 16:29
 * @since JDK 1.8
 **/

/**
 * @program: ruoyi
 * @description: 视频应用服务
 * @author: hesion
 * @create: 2020-12-31 16:29
 **/

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.hikvisionutils.HikVisionUtils;
import com.ruoyi.common.utils.hikvisionutils.model.HIKResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api("海康威视视频应用服务API")
@RestController
@RequestMapping("/videoapi/app")
public class VideoAppResourceController {

    //=======================编码设备信息=================
    // 这里的参数都用map接收，ResourceInfoController&AreaInfoController这两个Controller都采用了对象的方式，太蠢了。。。
    // 不过swagger api文档就没法直接看该传的参数，得查阅海康威视的V1.3的文档

    /**
     *@Author hst
     *@Description //TODO 分页获取编码设备列表，主要用于资源信息的全量同步。
     *@Date 16:42 2020/12/31
     *@Param [params]
     * @return com.ruoyi.common.core.domain.AjaxResult
     **/
    @ApiOperation("获取编码设备列表")
    @RequestMapping("/devicesList")
    public AjaxResult searchEncodeDevice(@RequestBody Map<String, Object> params) {
        String body = HikVisionUtils.getEncodeDevice(params).getBody();
        HIKResponseResult hikResponseResult = JSONObject.parseObject(body, HIKResponseResult.class);
        return AjaxResult.success(hikResponseResult.getData());
    }

    /**
     *@Author hst
     *@Description //TODO 查询目录下有权限的编码设备列表。
     *@Date 16:49 2020/12/31
     *@Param [params]
     * @return com.ruoyi.common.core.domain.AjaxResult
     **/
    @ApiOperation("查询编码设备列表")
    @RequestMapping(value = "/devicesSearch",method = RequestMethod.POST)
    public AjaxResult getEncodeDevice(@RequestBody Map<String, Object> params) {
        String body = HikVisionUtils.searchEncodeDevice(params).getBody();
        HIKResponseResult hikResponseResult = JSONObject.parseObject(body, HIKResponseResult.class);
        return AjaxResult.success(hikResponseResult.getData());
    }

    /**
     *@Author hst
     *@Description //TODO 根据资源编号查询单个编码设备详细信息，主要用于单个编码设备信息的展示。
     *@Date 16:53 2020/12/31
     *@Param [params]
     * @return com.ruoyi.common.core.domain.AjaxResult
     **/
    @ApiOperation("获取单个编码设备信息")
    @RequestMapping(value = "/deviceSingle",method = RequestMethod.POST)
    public AjaxResult getSingleDevice(@RequestBody Map<String, Object> params) {
        String body = HikVisionUtils.getSingleDevice(params).getBody();
        HIKResponseResult hikResponseResult = JSONObject.parseObject(body, HIKResponseResult.class);
        return AjaxResult.success(hikResponseResult.getData());
    }

    @ApiOperation("根据区域获取下级编码设备列表")
    @RequestMapping(value = "/deviceSubRegion",method = RequestMethod.POST)
    public AjaxResult getSubRegionDevice(@RequestBody Map<String, Object> params) {
        String body = HikVisionUtils.getSubRegionDevice(params).getBody();
        HIKResponseResult hikResponseResult = JSONObject.parseObject(body, HIKResponseResult.class);
        return AjaxResult.success(hikResponseResult.getData());
    }
    //=======================监控点信息==================
    @ApiOperation("查询监控点列表")
    @RequestMapping(value = "/cameraList",method = RequestMethod.POST)
    public AjaxResult getCameraList(@RequestBody Map<String, Object> params) {
        String body = HikVisionUtils.getCameraList(params).getBody();
        HIKResponseResult hikResponseResult = JSONObject.parseObject(body, HIKResponseResult.class);
        return AjaxResult.success(hikResponseResult.getData());
    }
    @ApiOperation("分页获取监控点资源")
    @RequestMapping(value = "/camerasPage",method = RequestMethod.POST)
    public AjaxResult getCamerasPage(@RequestBody Map<String, Object> params) {
        String body = HikVisionUtils.getCamerasPage(params).getBody();
        HIKResponseResult hikResponseResult = JSONObject.parseObject(body, HIKResponseResult.class);
        return AjaxResult.success(hikResponseResult.getData());
    }
    @ApiOperation("根据区域编号获取下级监控点列表")
    @RequestMapping(value = "/regionCameras",method = RequestMethod.POST)
    public AjaxResult getRegionCameras(@RequestBody Map<String, Object> params) {
        String body = HikVisionUtils.getRegionCameras(params).getBody();
        HIKResponseResult hikResponseResult = JSONObject.parseObject(body, HIKResponseResult.class);
        Map<String, Object> data = hikResponseResult.getData();
        if(null != data){
            // 获取list中的摄像头，然后给每个摄像头加上一个字段为摄像头类型
            List<Map<String, Object>> list = (List<Map<String, Object>>) data.get("list");
            for (int i = 0; i < list.size(); i++) {
                list.get(i).put("typeName","海康iSecureCenter");
            }
            data.put("list",list);
        }
        return AjaxResult.success(data);
    }
    @ApiOperation("根据编号获取监控点详细信息")
    @RequestMapping(value = "/camerasIndex",method = RequestMethod.POST)
    public AjaxResult getCamerasIndexCode(@RequestBody Map<String, Object> params) {
        String body = HikVisionUtils.getCamerasIndexCode(params).getBody();
        HIKResponseResult hikResponseResult = JSONObject.parseObject(body, HIKResponseResult.class);
        return AjaxResult.success(hikResponseResult.getData());
    }
}